package com.ims.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ims.dao.UserRoleCorMapper;
import com.ims.pojo.UserRoleCor;
import com.ims.service.UserRoleCorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yekka1
 * @description: TODO
 * @date 2022/9/7 20:47
 */

@Service
public class UserRoleCorServiceImpl extends ServiceImpl<UserRoleCorMapper, UserRoleCor> implements UserRoleCorService {

    @Autowired
    private UserRoleCorService userRoleCorService;

    /**
     * 依照userid在 table_user_role 中查找对应的 roleid
     *
     * @param userId
     */
    @Override
    public List<Integer> findRoleIdByUserId(int userId) {
        LambdaQueryWrapper<UserRoleCor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(UserRoleCor::getUserId, userId);
        List<UserRoleCor> list = userRoleCorService.list(queryWrapper);
        List<Integer> roleIdList = new ArrayList<>();
        for (UserRoleCor userRoleCor : list) {
            if (userRoleCor != null) {
                int roleId = userRoleCor.getRoleId();
                roleIdList.add(roleId);
            }
        }
        return roleIdList;
    }
}
